<?php
class ModelAccountCustomerBill extends Model {
    //customer_bill table type
    //1.take money(customer_bill table status: 1.complete 2.apply 3.preccessing 4.close)
    
    public function getCookerTakesMoney() {

        $query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "customer_bill` WHERE  customer_id = '" . (int)$this->customer->getId() . "' AND type='1' AND status!='4'");
        
        return $query->row['total'];
    }
    
    public function cookerTakeMoney($data)
    {
        $this->db->query("INSERT INTO " . DB_PREFIX . "customer_bill SET customer_id = '" . (int)$this->customer->getId() . "',total='".(float)$data['total']."',type='1',status='2',date_added=NOW(),date_modify=NOW()");
        $bill_id = $this->db->getLastId();
        $this->db->query("UPDATE " . DB_PREFIX . "customer SET money_took = '" . $this->getCookerTakesMoney() . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
        return $bill_id;
    }
}